package com.neu.wangweili.util;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBUtil {
    private  static ComboPooledDataSource dataSource=new ComboPooledDataSource();
    public static Connection getConnection() throws SQLException {
        return dataSource.getConnection();
    }
    public static void close(Connection conn, PreparedStatement stmt, ResultSet rst){
        if (conn!=null){
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }finally {
                conn=null;
            }
        }
        if (stmt!=null){
            try {
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }finally {
                    stmt=null;
            }
        }
        if (rst!=null){
            try {
                rst.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }finally {
                    rst=null;
            }
        }


    }
}
